<template>
  <div>
    <el-card class="main" body-style="height:100%">
      <div class="operater-bar">
        <el-descriptions
          class="des"
          title="老人健康数据"
          :column="3"
          :size="large"
          border
        >
          <el-descriptions-item width="140px">
            <template #label>
              <div class="cell-item">姓名</div>
            </template>
            {{ eldName }}
          </el-descriptions-item>
          <el-descriptions-item width="140px">
            <template #label>
              <div class="cell-item">年龄</div>
            </template>
            {{ eldAge }}
          </el-descriptions-item>
          <el-descriptions-item width="140px">
            <template #label>
              <div class="cell-item">性别</div>
            </template>
            {{ eldGender }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">体重（kg）</div>
            </template>
            {{ healthInfo.weight }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">身高（cm）</div>
            </template>
            {{ healthInfo.height }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">血常规</div>
            </template>
            {{ healthInfo.bloodrt }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">血压（mmHg）</div>
            </template>
            {{ healthInfo.bloodPressure }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">血脂（mmol/L）</div>
            </template>
            {{ healthInfo.bloodLipids }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">血糖（mg/dL）</div>
            </template>
            {{ healthInfo.bloodgLucose }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">尿常规</div>
            </template>
            {{ healthInfo.urinert }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">肾功能</div>
            </template>
            {{ healthInfo.renalFunction }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">肝功能</div>
            </template>
            {{ healthInfo.liverFunction }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label>
              <div class="cell-item">备注信息</div>
            </template>
            {{ healthInfo.remarks }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import { useStore } from "vuex";
import { computed } from "vue";
import * as user from "../../api/user.js";
const store = useStore();
const getAccId = computed(() => store.getters.getId);
const healthInfo = ref({
  hfId: "",
  eldId: "",
  bloodrt: "",
  urinert: "",
  liverFunction: "",
  bloodPressure: "",
  bloodLipids: "",
  bloodgLucose: "",
  weight: "",
  height: "",
  renalFunction: "",
  remarks: "",
  createTime: "",
  updateTime: "",
});
// 查找老人信息
let eldId = ref();
let eldName = ref();
let eldAge = ref();
let eldGender = ref();
console.log(getAccId.value);
const findelder = async () => {
  try {
    const res = await user.getElderAPI({
      accId: getAccId.value,
    });
    eldId.value = res.data.data[0].eldId;
    eldAge.value = res.data.data[0].eldAge;
    eldGender.value = res.data.data[0].eldGender;
    eldName.value = res.data.data[0].eldName;
    console.log(res.data.data[0]);
    //查找健康信息
    const params = ref({
      elderId: eldId.value,
    });
    user.getHealthAPI(params.value).then((reps) => {
      if (reps.data.code != 2000) {
        console.log("请求错误");
      } else {
        healthInfo.value.hfId = reps.data.data.hfId;
        healthInfo.value.bloodrt = reps.data.data.bloodrt;
        healthInfo.value.urinert = reps.data.data.urinert;
        healthInfo.value.liverFunction = reps.data.data.liverFunction;
        healthInfo.value.bloodPressure = reps.data.data.bloodPressure;
        healthInfo.value.bloodLipids = reps.data.data.bloodLipids;
        healthInfo.value.bloodgLucose = reps.data.data.bloodgLucose;
        healthInfo.value.weight = reps.data.data.weight;
        healthInfo.value.height = reps.data.data.height;
        healthInfo.value.renalFunction = reps.data.data.renalFunction;
        healthInfo.value.remarks = reps.data.data.remarks;
        healthInfo.value.createTime = reps.data.data.createTime;
        healthInfo.value.updateTime = reps.data.data.updateTime;
        //healthInfo.value = reps.data.data[0];
        console.log(healthInfo.value);
      }
    });
  } catch (error) {
    console.error("获取管理员信息失败:", error);
  }
};
findelder();
</script>

<style lang="less" scoped>
.main {
  width: 1175px;
  height: 575px;
}
.el-card__body {
  min-height: 100%;
}
.operater-bar {
  width: 100%;
  height: 100%;
  flex-direction: row;
  display: flex;
  justify-content: center;
  align-items: center;

  .des {
    width: 70%;
    height: 80%;
  }
}
</style>
